const fields = {

  // 基础信息与用户相关
  用户ID: "user_id",
  账户: "account",
  账户ID: "account_id",
  用户名: "user_name",
  密码: "password",
  用户类型: "user_type",
  性别: "gender",
  年龄: "age",
  生日: "birthday",
  姓名: "name",
  昵称: "nick_name",
  真实姓名: "real_name",
  头像: "avatar",
  签名: "signature",
  注册时间: "registration_time",
  登录IP: "login_ip",
  账户状态: "account_status",
  户名: "username",
  密码哈希: "password_hash",
  盐值: "salt",
  邮箱: "email",
  手机号: "phone_number",
  最后登录时间: "last_login_time",


  地址: "address",
  收货地址: "shipping_address",
  邮编: "postal_code",
  国家: "country",
  省份: "province",
  城市: "city",
  区县: "district",
  街道: "street",
  联系电话: "contact_phone",
  电子邮箱: "email",

  // 地址信息（扩展）
  地址ID: "address_id",
  收货人姓名: "recipient_name",
  收货人电话: "recipient_phone",
  详细地址: "detailed_address",
  默认地址: "default_address",
  订单ID: "order_id",
  订单号: "order_no",
  订单状态: "order_status",
  支付状态: "payment_status",
  发货状态: "shipping_status",
  金额: "amount",
  总金额: "total_amount",
  订单总金额: "order_total_amount",
  优惠金额: "discount_amount",
  实际支付金额: "actual_payment_amount",
  货币类型: "currency_type",
  下单时间: "order_time",
  发货时间: "shipping_time",
  收货时间: "delivery_time",

  // 订单发票信息
  发票ID: "invoice_id",
  "订单ID（发票关联）": "order_id_invoice",
  发票金额: "invoice_amount",
  开票时间: "invoicing_time",
  发票信息: "invoice_info",
  发票类型: "invoice_type",
  发票抬头: "invoice_title",
  发票内容: "invoice_content",

  商品ID: "product_id",
  商品编号: "product_no",
  产品编号: "product_id", // 重复项，需确认是否保留
  商品名称: "product_name",
  商品描述: "product_description",
  商品价格: "product_price",
  原价: "original_price",
  现价: "current_price",
  折扣价: "discount_price",
  商品数量: "product_quantity",
  库存数量: "stock_quantity",
  销售数量: "sold_quantity",
  商品图片: "product_image",
  商品规格: "product_specifications",
  类别ID: "category_id",
  商品类别ID: "category_id", // 重复项，需确认是否保留
  供应商ID: "supplier_id",
  上架时间: "shelf_time",
  下架时间: "unshelf_time",
  商品状态: "product_status",

  // 商品属性（扩展）
  商品品牌: "product_brand",
  商品产地: "product_origin",
  商品材质: "product_material",
  商品适用人群: "product_target_audience",
  商品保修期: "product_warranty_period",

  // 商品规格（扩展）
  商品规格ID: "product_specification_id",
  规格名称: "specification_name",
  规格值: "specification_value",
  规格图片: "specification_image",

  供应商名称: "supplier_name",
  供应商联系信息: "supplier_contact_info",
  供应商联系方式: "supplier_contact",
  供应商地址: "supplier_address",
  供应商评级: "supplier_rating",


  优惠券ID: "coupon_id",
  优惠券代码: "coupon_code",
  优惠券名称: "coupon_name",
  优惠券金额: "coupon_amount",
  优惠券有效期: "coupon_expiry_date",
  优惠券有效期开始: "coupon_start_date",
  优惠券有效期结束: "coupon_end_date",
  优惠券使用状态: "coupon_usage_status",
  优惠券类型: "coupon_type",
  优惠券使用条件: "coupon_usage_conditions",

  积分: "points",
  积分余额: "points_balance",
  积分ID: "points_id",
  积分来源: "points_source",
  积分数量: "points_amount",
  积分使用时间: "points_usage_time",
  当前积分: "current_points",

  购物车ID: "cart_id",
  购物车商品ID: "cart_product_id",
  购物车商品数量: "cart_product_quantity",
  加入购物车时间: "add_to_cart_time",

  支付ID: "payment_id",
  支付类型: "payment_type",
  支付方式: "payment_method",
  支付时间: "payment_time",
  支付金额: "payment_amount",

  // 支付网关
  支付网关ID: "payment_gateway_id",
  支付网关名称: "payment_gateway_name",
  支付网关类型: "payment_gateway_type",
  支付网关配置: "payment_gateway_config",
  支付网关状态: "payment_gateway_status",

  // 物流
  物流ID: "logistics_id",
  物流公司: "logistics_company",
  物流单号: "logistics_no",
  流单号: "logistics_tracking_number", // 重复或错误项，需确认
  物流状态: "logistics_status",
  发货人: "shipper",
  收货人: "recipient",
  物流跟踪信息: "logistics_tracking_info",
  预计到达时间: "estimated_arrival_time",

  //评价
  评价: "review",
  评价内容: "review_content",
  评价分数: "review_score",
  评价时间: "review_time",
  评价ID: "review_id",
  评价星级: "review_rating",

  // 商品评论回复
  回复ID: "reply_id",
  回复内容: "reply_content",
  回复时间: "reply_time",

  // 客户服务
  客户ID: "customer_id",
  客户名称: "customer_name",
  客户等级: "customer_level",
  服电话: "customer_service_phone",
  在线客服状态: "online_customer_service_status",
  客服评价: "customer_service_rating",

  会员ID: "membership_id",
  会员等级: "membership_level",
  会员积分: "membership_points",
  会员等级升级条件: "membership_level_up_conditions",
  会员特权: "membership_privileges",
  会员注册时间: "membership_registration_time",
  会员最后登录时间: "membership_last_login_time",

  // 用户权限

  设置ID: "setting_id",
  设置名称: "setting_name",
  设置值: "setting_value",
  描述: "setting_description",

  角色ID: "role_id",
  角色名称: "role_name",
  角色描述: "role_description",
  权限列表: "permissions",
};

const tables = {
  // 基础信息与用户相关
  用户信息表: "user_info",
  用户账户表: "user_account",
  登录信息: "user_login",
  用户登录日志表: "user_login_log",
  用户权限表: "user_permission",
  用户角色表: "user_role",
  用户角色关联表: "user_role_relation",

  // 订单与支付相关
  订单信息表: "order_info",
  订单详情表: "order_detail",
  支付记录表: "payment_record",
  退款记录表: "refund_record",
  购物车表: "shopping_cart",

  // 商品与库存相关
  商品信息表: "product_info",
  商品分类表: "product_category",
  商品库存表: "product_inventory",
  商品评价表: "product_review",

  // 内容管理相关
  文章信息表: "article_info",
  文章分类表: "article_category",
  评论表: "comment",
  标签表: "tag",
  标签关联表: "tag_relation",

  // 系统与日志相关
  系统日志表: "system_log",
  操作日志表: "operation_log",
  错误日志表: "error_log",

  // 营销与活动相关
  优惠券信息表: "coupon_info",
  优惠券使用记录表: "coupon_use_record",
  活动信息表: "activity_info",
  活动参与记录表: "activity_participation",

  // 社交与关系相关
  好友关系表: "friend_relation",
  关注关系表: "follow_relation",
  消息表: "message",

  // 地址与物流相关
  收货地址表: "shipping_address",
  物流信息表: "logistics_info",

  // 其他常用表
  配置参数表: "config_parameter",
  附件表: "attachment",
  反馈表: "feedback",
  公告表: "announcement",

  用户积分表: "user_points",
  用户等级表: "user_level",
  用户偏好设置表: "user_preference",

  // 订单与支付相关
  发票信息表: "invoice_info",
  订单状态变更记录表: "order_status_change",

  // 商品与库存相关
  商品规格表: "product_specification",
  商品属性表: "product_attribute",
  商品图片表: "product_image",

  // 内容管理相关
  回复表: "reply",
  页面内容表: "page_content",

  // 系统与日志相关
  性能监控表: "performance_monitor",

  // 营销与活动相关
  促销规则表: "promotion_rule",
  促销应用记录表: "promotion_application",

  // 社交与关系相关
  消息接收者表: "message_recipient",
  群组信息表: "group_info",
  群组成员表: "group_member",

  // 地址与物流相关
  物流公司表: "logistics_company",
  物流跟踪记录表: "logistics_tracking",

  // 电商特定表
  商品收藏表: "product_favorite",
  店铺信息表: "store_info",
  店铺评价表: "store_review",
  购物车商品表: "cart_item",

  // 其他常用表
  语言表: "language",
  "国家/地区表": "country_region",
  货币表: "currency",
  时区表: "timezone",
};

function find(query: string, obj: any) {
  const results: string[] = [];
  Object.keys(obj).forEach((key) => {
    if (key.toLowerCase().includes(query.toLowerCase())) {
      results.push(obj[key]);
    }
  });
  return results;
}
export function findInTable(query: string) {
  return find(query, tables);
}
export function findInFields(query: string) {
  return find(query, fields);
}

import { pinyin as py } from 'pinyin-pro';
export function getFieldName(chineseName: string) {
  if (chineseName === '') return '';
  let english = findInFields(chineseName);
  if (english && english.length > 0) return english;
  let result = py(chineseName, { toneType: 'none', type: 'array' }).join('_');
  return [result];
};
export function getTableName(chineseName: string) {
  if (chineseName === '') return '';
  let english = findInTable(chineseName);
  if (english && english.length > 0) return english;
  let result = py(chineseName, { toneType: 'none', type: 'array' }).join('_');
  return [result];
};